package com.ruoyi.controller;



import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.domain.Company;
import com.ruoyi.service.ICompanyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

@RestController
@RequestMapping("/company")
public class CompanyController {

/**
 *  Company /  company
 */

    @Autowired
    private ICompanyService companyService;


    @GetMapping("/list")
    // 全查
    public AjaxResult list(){
        List<Company> list = companyService.list();
        return AjaxResult.success(list);
    }
    @GetMapping("/{id}")
    // 根据id 查一条
    public Company getInfo(@PathVariable Long id){
        System.out.println("id = " + id);
        Company company = companyService.getById(id);
        return company;
    }
    @PostMapping()
    // 添加
    public AjaxResult add(@RequestBody Company company){
        System.out.println("company = " + company);
        int add = companyService.save(company);
        return add>0?AjaxResult.success("success"):AjaxResult.error("error");
    }
    @PutMapping()
    // 修改
    public AjaxResult edit(@RequestBody Company company){
        System.out.println("company = " + company);
        int edit = companyService.updateById(company);
        return edit>0?AjaxResult.success("success"):AjaxResult.error("error");
    }

//    @DeleteMapping("/{id}")
//    // 根据id 删除一条
//    public int deleteOne(@PathVariable Long id){
//        System.out.println("id = " + id);
//        int delete = companyService.removeById(id);
//        return delete;
//    }
    @DeleteMapping("/{ids}")
    // 根据id 删除一条
    public AjaxResult deleteOne(@PathVariable Long[] ids){
        System.out.println("ids = " + Arrays.toString(ids));
        int delete = companyService.removeByIds(ids);
        return delete>0?AjaxResult.success("success"):AjaxResult.error("error");
    }
}
